home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / aijournl / 1986_12 / neurosim.dec < prev   
Text File  |  1986-12-09  |  25KB  |  686 lines

  1.  
  2.  
  3.                "Catching Knowledge in Neuro Nets"
  4.                       by Charles Jorgensen
  5.             Full length version of code from article
  6.  
  7.  
  8.                           NEUROSIM.BAS
  9.  
  10. 10  ON ERROR GOTO 30000
  11. 20 REM ************************************************************************
  12. 30 REM * Experimental Network System                written in GW-BASIC 2.02  *
  13. 40 REM * C.J. Matheus & C.C. Jorgensen                         Sept 24, 1986  *
  14. 50 REM *                                                                      *
  15. 60 REM * This software may be freely used for educational purposes only.      *
  16. 70 REM * Reproduction and distribution is allowed provided this statement     *
  17. 80 REM * and the authors' names are included.                                 *
  18. 90 REM *                                                                      *
  19. 100 REM ************************************************************************
  20. 110 REM ********************
  21. 120 REM  SYSTEM PARAMETERS
  22. 130 REM ********************
  23. 140 MATRIXLOADED = 0    ' flag to test if matrix is loaded
  24. 150 PARAMETERS = 6
  25. 160 DIM PARAM(PARAMETERS), PARAM$(PARAMETERS)
  26. 170 PARAM$(1) = "Number of nodes in network                           "
  27. 180 PARAM(1) = 25
  28. 190 PARAM$(2) = "Evaluation procedure (0 = Hopfield, 1 = S. Annealing)"
  29. 200 PARAM(2) = 0    ' Evaluation procedure for new states
  30. 210 INITTEMP = 8    ' Initial temperature for simulated annealing
  31. 220 TEMPDECR = 2    ' temperature decrement per cycle
  32. 230 PARAM$(3) = "Percent of nodes firing per cycle                    "
  33. 240 PARAM(3) = 100  ' 100 percent of nodes fire each cycle
  34. 250 PARAM$(4) = "Single node threshold value                          "
  35. 260 PARAM(4) = 0    ' threshold that must be exceeded for node to turn on
  36. 270 PARAM$(5) = "Learning rule (1=Hopfield, 2=Hebbian, 3=Heb/anti-Heb)"
  37. 280 PARAM(5) = 1    ' rule used to adjust connection weights
  38. 290 LEARNRULE$(1) = "Hopfield [(2Vi - 1)(2Vj - 1)]"
  39. 300 LEARNRULE$(2) = "Hebbian [Vi * Vj]"
  40. 310 LEARNRULE$(3) = "Hebb/anit-Hebb [(2Vi - 1) * Vj]"
  41. 320 PARAM$(6) = "Input biasing factor                                 "
  42. 330 PARAM(6) = 0    ' factor mutiplied by input state and added to input sum
  43. 340 DIM WEIGHT(PARAM(1),PARAM(1))    ' connection weight matrix
  44. 350 DIM STATE(PARAM(1))              ' state vector
  45. 360 DIM NEWSTATE(PARAM(1))           ' new-state vector
  46. 370 DIM INPUTVECTOR(PARAM(1))        ' input state vector (for input biasing)
  47. 400 REM *********************
  48. 410 REM *** INITIAL SETUP ***
  49. 420 REM *********************
  50. 430 CLS
  51. 440 PRINT "                       Experimental Network System"
  52. 450 PRINT "                                   by"
  53. 460 PRINT "                      C.J. Matheus & C.C. Jorgensen"
  54. 470 PRINT
  55. 480 PRINT
  56. 490 PRINT
  57. 500 PRINT "                       Initial Network Description"
  58. 510 PRINT "                       ---------------------------"
  59. 520 GOSUB 11000    ' describe network
  60. 530 PRINT
  61. 540 INPUT "Change initial network <NO>"; ANSWER$
  62. 550 IF LEFT$(ANSWER$,1) = "y" OR LEFT$(ANSWER$,1) = "Y" THEN GOSUB 4000
  63. 560 FOR I = 1 TO PARAM(1)
  64. 570     READ STATE(I)
  65. 580 NEXT I
  66. 590 CLS
  67. 600 PRINT "Initial ";
  68. 610 GOSUB 6000   ' print initial pattern
  69. 700 REM *********************
  70. 710 REM ***               ***
  71. 720 REM ***   Main Loop   ***
  72. 730 REM ***               ***
  73. 740 REM *********************
  74. 750 WHILE COMMAND <> 9
  75. 760 GOSUB 11000    ' describe network
  76. 770    PRINT "Options:     1 = learn"
  77. 780    PRINT "             2 = recall"
  78. 790    PRINT "             3 = change parameters"
  79. 800    PRINT "             4 = display/change state vector"
  80. 810    PRINT "             5 = save state vector in file"
  81. 820    PRINT "             6 = display weight matrix"
  82. 830    PRINT "             7 = load matrix from file"
  83. 840    PRINT "             8 = save matrix to file"
  84. 850    PRINT "             9 = quit"
  85. 860    PRINT
  86. 870    INPUT "Option choice"; COMMAND
  87. 880    ON COMMAND GOSUB 2000,3000,4000,5000,7000,8000,9000,10000
  88. 890 WEND
  89. 900 GOTO 32050
  90. 1000 REM *********************
  91. 1010 REM ****             ****
  92. 1020 REM **** SUBROUTINES ****
  93. 1030 REM ****             ****
  94. 1040 REM *********************
  95. 1050 REM
  96. 2000 REM ********************
  97. 2010 REM   LEARN SUBROUTINE
  98. 2020 REM ********************
  99. 2030 CLS
  100. 2040 PRINT "Learn ";
  101. 2050 GOSUB 5040   ' Display and change state
  102. 2060 LOCATE 11,1
  103. 2070 PRINT "Loading pattern into weight matrix:"
  104. 2080 PRINT "Using "; LEARNRULE$(PARAM(5)) ;" learning rule."
  105. 2090 ON PARAM(5) GOSUB 2180,2320,2460
  106. 2100 CLS
  107. 2110 PRINT "Learned ";
  108. 2120 GOSUB 6000
  109. 2130 MATRIXLOADED = 1    ' turn matix loaded flag on
  110. 2140 RETURN
  111. 2150 REM *****************************************
  112. 2160 REM         Learning Rule Subroutines
  113. 2170 REM *****************************************
  114. 2180     REM *************************************
  115. 2190     REM Hopfield leanring rule (2Vi-1)(2Vj-1)
  116. 2200     REM *************************************
  117. 2210     FOR I = 1 TO PARAM(1) - 1
  118. 2220         LOCATE 11,40
  119. 2230         PRINT I
  120. 2240         FOR J = I + 1 TO PARAM(1)
  121. 2250             LOCATE 11,45
  122. 2260             PRINT J
  123. 2270             WEIGHT(I,J) = WEIGHT(I,J) + (2 * STATE(I) - 1) * (2 * STATE(J) - 1)
  124. 2280             WEIGHT(J,I) = WEIGHT(I,J)
  125. 2290         NEXT J
  126. 2300     NEXT I
  127. 2310     RETURN
  128. 2320     REM *************************************
  129. 2330     REM    Hebbian learning rule:  Vi*Vj
  130. 2340     REM *************************************
  131. 2350     FOR I = 1 TO PARAM(1) - 1
  132. 2360         LOCATE 11,40
  133. 2370         PRINT I
  134. 2380         FOR J = I + 1 TO PARAM(1)
  135. 2390             LOCATE 11,45
  136. 2400             PRINT J
  137. 2410             WEIGHT(I,J) = WEIGHT(I,J) + STATE(I) * STATE(J)
  138. 2420             WEIGHT(J,I) = WEIGHT(I,J)
  139. 2430         NEXT J
  140. 2440     NEXT I
  141. 2450     RETURN
  142. 2460     REM ********************************************************
  143. 2470     REM    Hebbian/anit-Hebbian learning rule:  (2Vi - 1) * Vj
  144. 2480     REM ********************************************************
  145. 2490     REM This rule takes more time since the matrix is not necc. symetric
  146. 2500     FOR I = 1 TO PARAM(1)
  147. 2510         LOCATE 11,40
  148. 2520         PRINT I
  149. 2530         FOR J = 1 TO PARAM(1)
  150. 2540             IF I = J THEN GOTO 2580
  151. 2550             LOCATE 11,45
  152. 2560             PRINT J
  153. 2570             WEIGHT(I,J) = WEIGHT(I,J) + (2 * STATE(I) - 1) * STATE(J)
  154. 2580         NEXT J
  155. 2590     NEXT I
  156. 2600     RETURN
  157. 3000 REM ********************
  158. 3010 REM   RECALL SUBROUTINE
  159. 3020 REM ********************
  160. 3030 CLS
  161. 3040 IF MATRIXLOADED THEN GOTO 3090
  162. 3050 BEEP
  163. 3060 PRINT "Weight matrix is empty!"
  164. 3070 PRINT "Run either the 'learn' or 'load matrix' option before 'recall'."
  165. 3080 GOTO 3420
  166. 3090 GOSUB 5040    ' displat/change state vector
  167. 3100 FOR I = 1 TO PARAM(1)
  168. 3110     INPUTVECTOR(I) = (2 * STATE(I) - 1)
  169. 3120 NEXT I
  170. 3130 DEF FNEVALUATE(INDEX) = PARAM(3) - (100 * RND(1))
  171. 3140 IF PARAM(2) = 0 THEN GOTO 3240
  172. 3150    REM Simulated annealing options
  173. 3160    PRINT
  174. 3170    PRINT "Simulated Annealing: Initial temperature <"; INITTEMP ;">";
  175. 3180    INPUT ANSWER
  176. 3190    IF ANSWER THEN INITTEMP = ANSWER
  177. 3200    PRINT "                     Temperature decrement <"; TEMPDECR ;">";
  178. 3210    INPUT ANSWER
  179. 3220    IF ANSWER THEN TEMPDECR = ANSWER
  180. 3230    TEMP = INITTEMP
  181. 3240 ANSWER$ = "YES"
  182. 3250 WHILE LEFT$(ANSWER$, 1) <> "N" AND LEFT$(ANSWER$, 1) <> "n"
  183. 3260    LOCATE 12,1
  184. 3270    PRINT SPACE$(79)
  185. 3280    LOCATE 12,1
  186. 3290    PRINT "Evaluating nodes";
  187. 3300    ON PARAM(2) + 1 GOSUB 3430,3610    ' Evaluate subroutines
  188. 3310    FOR I = 1 TO PARAM(1)
  189. 3320        STATE(I) = NEWSTATE(I)
  190. 3330    NEXT I
  191. 3340    PRINT
  192. 3350    GOSUB 6000 ' print state vector
  193. 3360    INPUT "Cycle again <YES>"; ANSWER$
  194. 3370    LOCATE CSRLIN - 1, 1
  195. 3380    PRINT SPACE$(30)
  196. 3390 WEND
  197. 3400 CLS
  198. 3410 GOSUB 6000    ' Print state vector
  199. 3420 RETURN
  200. 3430    REM ***********************************
  201. 3440    REM   Evaluation Subroutines
  202. 3450    REM ***********************************
  203. 3460        REM *******************************
  204. 3470        REM   Straight threshold function
  205. 3480        REM *******************************
  206. 3490        FOR I= 1 TO PARAM(1)
  207. 3500            IF FNEVALUATE(I) <= 0 THEN GOTO 3590
  208. 3510            SUM = 0
  209. 3520            PRINT ".";
  210. 3530            FOR J = 1 TO PARAM(1)
  211. 3540                SUM = SUM + WEIGHT(J,I) * STATE(J)
  212. 3550            NEXT J
  213. 3560            REM  E = SUMj(Vj * Wij) + (INPUT * INPUT-BIAS) - THRESHOLD
  214. 3570            SUM = SUM - PARAM(4) + (INPUTVECTOR(I) * PARAM(6))
  215. 3580            IF SUM > 0 THEN NEWSTATE(I) = 1 ELSE NEWSTATE(I) = 0
  216. 3590        NEXT I
  217. 3600        RETURN
  218. 3610        REM **************************
  219. 3620        REM  Simulated Annealing
  220. 3630        REM **************************
  221. 3640        PRINT " (temp =" TEMP ;")";
  222. 3650        FOR I= 1 TO PARAM(1)
  223. 3660            IF FNEVALUATE(I) <= 0 THEN GOTO 3760
  224. 3670            SUM = 0
  225. 3680            PRINT ".";
  226. 3690            FOR J = 1 TO PARAM(1)
  227. 3700                SUM = SUM + WEIGHT(J,I) * STATE(J)
  228. 3710            NEXT J
  229. 3720            REM  E = SUMj(Vj * Wij) + (INPUT * INPUT-BIAS) - THRESHOLD
  230. 3730            SUM = SUM - PARAM(4) + (INPUTVECTOR(I) * PARAM(6))
  231. 3740            PROB = 1 / (1 + EXP(-SUM/ TEMP))
  232. 3750            IF PROB > RND(1) THEN NEWSTATE(I) = 1 ELSE NEWSTATE(I) = 0
  233. 3760        NEXT I
  234. 3770        TEMP = TEMP - TEMPDECR
  235. 3780        IF TEMP <= 0 THEN TEMP = .5
  236. 3790        RETURN
  237. 4000 REM ********************
  238. 4010 REM  CHANGE PARAMETERS
  239. 4020 REM ********************
  240. 4030 CLS
  241. 4040 PRINT
  242. 4050 PRINT "System parameters:"
  243. 4060 PRINT
  244. 4070 FOR I = 1 TO PARAMETERS
  245. 4080    PRINT I;") "; PARAM$(I);" = "; PARAM(I)
  246. 4090 NEXT I
  247. 4100 PRINT
  248. 4110 INPUT "Parameter # to change <none>"; PNUM
  249. 4120 IF PNUM > PARAMETERS OR PNUM = 0 THEN 4150
  250. 4130 INPUT "New value"; PARAM(PNUM)
  251. 4140 GOTO 4030
  252. 4150 CLS
  253. 4160 RETURN
  254. 5000 REM ********************
  255. 5010 REM     CHANGE STATE
  256. 5020 REM ********************
  257. 5030 CLS
  258. 5040 GOSUB 6000    ' display pattern
  259. 5050 INPUT "Change pattern <NO>"; ANSWER$
  260. 5060 IF LEFT$(ANSWER$,1) <> "Y" AND LEFT$(ANSWER$,1) <> "y" THEN GOTO 5510
  261. 5070 PRINT
  262. 5080 INPUT "Get pattern from FILE or CHANGE current pattern <FILE>"; ANSWER$
  263. 5090 IF LEFT$(ANSWER$,1) = "C" OR LEFT$(ANSWER$,1) = "c" THEN GOTO 5250
  264. 5100 PRINT
  265. 5110 PRINT "Pattern files available:"
  266. 5120 PRINT
  267. 5130 FILES "*.pat"
  268. 5140 PRINT
  269. 5150 INPUT "File to load <none>"; FILENAME$
  270. 5160 IF FILENAME$ = "" OR FILENAME$ = "none" OR FILENAME$ = "NONE" THEN GOTO 5000
  271. 5170 IF INSTR(".",FILENAME$) = 0 THEN FILENAME$ = FILENAME$ + ".pat"
  272. 5180 OPEN FILENAME$ FOR INPUT AS #1
  273. 5190 FOR I = 1 TO PARAM(1)
  274. 5200     INPUT #1, STATE(I)
  275. 5210 NEXT I
  276. 5220 CLOSE #1
  277. 5230 CLS
  278. 5240 GOTO 5000
  279. 5250 REM ***  Create new pattern  ***
  280. 5260 CLS
  281. 5270 GOSUB 6000   ' Display state
  282. 5280 ROWLEN = SQR(PARAM(1))
  283. 5290 XINPUT = ROWLEN + 4
  284. 5300 LOCATE 12,1
  285. 5310 PRINT "To change the current state of each node respond to the prompts"
  286. 5320 PRINT "with either a 0 or 1 to turn on or off the state of the node "
  287. 5330 PRINT "pointed to by the uparrow;  all other responses leave the state"
  288. 5340 PRINT "unchanged."
  289. 5350 FOR I = 1 TO PARAM(1)
  290. 5360     Y = (((I - 1) MOD ROWLEN)+ 1) * 2
  291. 5370     X = INT((I - 1) / ROWLEN ) + 3
  292. 5380     LOCATE X + 1,Y
  293. 5390     PRINT "^"
  294. 5400     LOCATE XINPUT, 1
  295. 5410     INPUT "Node state <unchanged>"; STATE$
  296. 5420     IF STATE$ = "1" THEN STATE(I) = 1
  297. 5430     IF STATE$ = "0" THEN STATE(I) = 0
  298. 5440     LOCATE X,Y
  299. 5450     IF STATE(I) THEN PRINT "*" ELSE PRINT " "
  300. 5460     LOCATE X + 1,Y
  301. 5470     IF STATE(I + ROWLEN) THEN PRINT "*" ELSE PRINT " "
  302. 5480 NEXT I
  303. 5490 CLS
  304. 5500 GOTO 5040
  305. 5510 LOCATE CSRLIN - 1, 1
  306. 5520 PRINT SPACE$(40)
  307. 5530 LOCATE CSRLIN - 2, 1
  308. 5540 RETURN
  309. 6000 REM ********************
  310. 6010 REM   PRINT SUBROUTINE
  311. 6020 REM ********************
  312. 6030 ROWLEN = SQR(PARAM(1))
  313. 6040 PRINT "Pattern:"
  314. 6050 FOR I = 1 TO ROWLEN
  315. 6060     PRINT
  316. 6070     FOR J = 1 TO ROWLEN
  317. 6080         IF STATE( ROWLEN * (I - 1) + J ) THEN PRINT " *"; ELSE PRINT "  ";
  318. 6090     NEXT J
  319. 6100 NEXT I
  320. 6110 PRINT
  321. 6120 PRINT
  322. 6130 RETURN
  323. 7000 REM ********************
  324. 7010 REM   SAVE STATE FILE
  325. 7020 REM ********************
  326. 7030 GOSUB 5000
  327. 7040 PRINT
  328. 7050 PRINT "Pattern files:"
  329. 7060 PRINT
  330. 7070 FILES "*.pat"
  331. 7080 PRINT
  332. 7090 INPUT "File name to save state in <none>"; FILENAME$
  333. 7100 IF FILENAME$ = "" OR FILENAME$ = "none" THEN GOTO 7250
  334. 7110 IF INSTR(".",FILENAME$) = 0 THEN FILENAME$ = FILENAME$ + ".pat"
  335. 7120 OPEN FILENAME$ FOR OUTPUT AS #1
  336. 7130 CLS
  337. 7140 PRINT
  338. 7150 PRINT
  339. 7160 PRINT "Saving state";
  340. 7170 FOR I = 1 TO PARAM(1)
  341. 7180     PRINT #1, STATE(I)
  342. 7190       PRINT ".";
  343. 7200 NEXT I
  344. 7210 PRINT
  345. 7220 PRINT
  346. 7230 CLOSE #1
  347. 7240 PRINT "State saved in "; FILENAME$
  348. 7250 RETURN
  349. 8000 REM *********************
  350. 8010 REM  DISPLAY WEIGHT MATRIX
  351. 8020 REM *********************
  352. 8030 PRINT "Weight Matrix:"
  353. 8040 FOR I = 1 TO PARAM(1)
  354. 8050    PRINT
  355. 8060     FOR J = 1 TO PARAM(1)
  356. 8070         PRINT WEIGHT(I,J);
  357. 8080     NEXT J
  358. 8090 NEXT I
  359. 8100 PRINT
  360. 8110 INPUT "Press CR to continue"; ANSWER$
  361. 8120 CLS
  362. 8130 RETURN
  363. 9000 REM ********************
  364. 9010 REM   LOAD MATRIX FILE
  365. 9020 REM ********************
  366. 9030 CLS
  367. 9040 PRINT "Available matrix files:"
  368. 9050 PRINT
  369. 9060 FILES "*.mat"
  370. 9070 PRINT
  371. 9080 INPUT "File to load <none>"; FILENAME$
  372. 9090 IF FILENAME$ = "" OR FILENAME$ = "none" OR FILENAME$ = "NONE" THEN GOTO 9270
  373. 9100 IF INSTR(".",FILENAME$) = 0 THEN FILENAME$ = FILENAME$ + ".mat"
  374. 9110 OPEN FILENAME$ FOR INPUT AS #1
  375. 9120 CLS
  376. 9130 PRINT
  377. 9140 PRINT
  378. 9150 PRINT "Loading matrix:"
  379. 9160 FOR I = 1 TO PARAM(1)
  380. 9170     LOCATE 3,17
  381. 9180     PRINT I
  382. 9190     FOR J = 1 TO PARAM(1)
  383. 9200         INPUT #1, WEIGHT(I,J)
  384. 9210     NEXT J
  385. 9220 NEXT I
  386. 9230 CLOSE #1
  387. 9240 PRINT
  388. 9250 PRINT FILENAME$; " loaded into matrix."
  389. 9260 MATRIXLOADED = 1    ' turn matix loaded flag on
  390. 9270 RETURN
  391. 10000 REM ********************
  392. 10010 REM   SAVE MATRIX FILE
  393. 10020 REM ********************
  394. 10030 CLS
  395. 10040 PRINT "Matrix files:"
  396. 10050 FILES "*.mat"
  397. 10060 PRINT
  398. 10070 INPUT "File name to save matrix under <none>"; FILENAME$
  399. 10080 IF FILENAME$ = "" THEN GOTO 10250
  400. 10090 IF INSTR(".",FILENAME$) = 0 THEN FILENAME$ = FILENAME$ + ".mat"
  401. 10100 OPEN FILENAME$ FOR OUTPUT AS #1
  402. 10110 CLS
  403. 10120 PRINT
  404. 10130 PRINT
  405. 10140 PRINT "Saving Matrix:"
  406. 10150 FOR I = 1 TO PARAM(1)
  407. 10160     LOCATE 3,16
  408. 10170     PRINT I
  409. 10180     FOR J = 1 TO PARAM(1)
  410. 10190         PRINT #1, WEIGHT(I,J)
  411. 10200     NEXT J
  412. 10210 NEXT I
  413. 10220 CLOSE #1
  414. 10230 PRINT
  415. 10240 PRINT "Matrix saved in "; FILENAME$
  416. 10250 RETURN
  417. 11000 REM *********************
  418. 11010 REM ***  DESCRIBE NET ***
  419. 11020 REM *********************
  420. 11030 PRINT
  421. 11040 IF PARAM(2) THEN PRINT "Sim Annealing"; ELSE PRINT "Hopfield-like";
  422. 11050 PRINT " network: size ="; PARAM(1) ;"threshold ="; PARAM(4) ;
  423. 11060 PRINT " input bias ="; PARAM(6) ;" fire% ="; PARAM(3)
  424. 11070 PRINT SPACE$(23);
  425. 11080  PRINT "learning rule = "; LEARNRULE$(PARAM(5))
  426. 11090 PRINT
  427. 11100 RETURN
  428. 20000 REM *********************
  429. 20010 REM ***               ***
  430. 20020 REM ***     data      ***
  431. 20030 REM ***               ***
  432. 20040 REM *********************
  433. 20050 REM  Initial pattern: "o"
  434. 20060 DATA 1, 1, 1, 1, 1
  435. 20070 DATA 1, 0, 0, 0, 1
  436. 20080 DATA 1, 0, 0, 0, 1
  437. 20090 DATA 1, 0, 0, 0, 1
  438. 20100 DATA 1, 1, 1, 1, 1
  439. 30000 REM *********************
  440. 30010 REM ***               ***
  441. 30020 REM *** ERROR HANDLER ***
  442. 30030 REM ***               ***
  443. 30040 REM *********************
  444. 30050 IF ERR <> 53 THEN 30150
  445. 30060 IF ERL = 5130 THEN RESUME 5140
  446. 30070 IF ERL = 7070 THEN RESUME 7080
  447. 30080 IF ERL = 9060 THEN RESUME 9070
  448. 30090 IF ERL = 10050 THEN RESUME 10060
  449. 30100 PRINT "File not found."
  450. 30110 IF ERL = 5180 THEN RESUME 5140
  451. 30120 IF ERL = 7120 THEN RESUME 7080
  452. 30130 IF ERL = 9110 THEN RESUME 9070
  453. 30140 IF ERL = 10100 THEN RESUME 10060
  454. 30150 IF ERL <> 5470 THEN GOTO 30180
  455. 30160    PRINT " "
  456. 30170    RESUME 5480
  457. 30180 PRINT "Error #"; ERR ;"at line"; ERL
  458. 30190 PRINT "Continuing at main loop..."
  459. 30200 CLOSE
  460. 30210 RESUME 700
  461. 32000 REM *********************
  462. 32010 REM ***               ***
  463. 32020 REM ***  END PROGRAM  ***
  464. 32030 REM ***               ***
  465. 32040 REM *********************
  466. 32050 CLOSE
  467. 32060 ON ERROR GOTO 0    ' turn off error trapping
  468. 32767 END
  469.  
  470.  
  471.  
  472.                   README file for NEUROSIM.BAS 
  473.  
  474.  
  475. ------------------------------------
  476. NEUROSIM is written in GW-BASIC 2.02
  477. ------------------------------------
  478.  
  479. An Experimental Network System
  480. conceived and written by:   C.J. Matheus & C.C. Jorgensen
  481.  
  482. This program is intended to provide the user with a feel for some of the
  483. the various aspects of programming neural networks.  The user is presented 
  484. with several parameters which may be altered to produce different versions 
  485. of Hopfield-like or Boltzmann-like networks.  Also included are three 
  486. different types of learning rules:  Hopfield (2*Vi - 1)(2*Vj - 1), 
  487. Hebbian (Vi * Vj), and Hebbian/anti-Hebbian (2*Vi - 1) * Vj.  While this 
  488. system is intended to be purely educational it does have the capabilities 
  489. of some full fledged network systems and is limited primarily by its size 
  490. and speed.
  491.  
  492. The basic network consists of 25 nodes (or neurons), totally interconnected
  493. through a weight matrix W.  For visual purposes the state vector of the
  494. network is laid out as a 5 by 5 matrix.  Patterns are created in the state
  495. vector (usually alphabetic character representations) and then loaded into
  496. the weight matrix through a "learn"ing procedure or recalled from the matrix
  497. through the "recall" process.
  498.  
  499. When the program is run the default network configuration is described: a
  500. Hopfield-like 25 node network with threshold = 0, input bias = 0, and fire
  501. percent = 100.  The default learning rule is the Hopfield rule.  These
  502. parameters can be changed initially or at any other time using the "change
  503. parameters" option.
  504.  
  505. The network is initially loaded with a pattern representing the letter 'O':
  506.  
  507.      Initial Pattern:
  508.  
  509. * * * * *
  510. *       *
  511. *       *
  512. *       *
  513. * * * * *
  514.  
  515. This pattern (or any other state pattern) can be changed with the
  516. "display/change state vector" option (most other options also allow you to
  517. change the pattern).  The weight matrix is initially empty and must be
  518. taught or loaded before recall is allowed.
  519.  
  520. After describing the network configuration and displaying the initial
  521. pattern the program enters the main option loop.  The options available
  522. are:
  523. 1) learn
  524. takes the pattern in the state vector and stores it
  525. into the weight matrix according to the current learning rule.
  526.  
  527. 2) recall
  528. uses the current state vector as the initial "cue" pattern
  529. and recalls the closest and/or strongest pattern retrievable 
  530. from the weight matrix.  Recall is not allowed unless
  531. the matrix has first been loaded with either the "learn" or 
  532. "load matrix" option.
  533.  
  534. 3) change parameters
  535. allows the user to change the 6 major system parameters:
  536.  
  537. 1) Number of nodes in network
  538. the number of nodes is initially set to 25.
  539. It is not recommended that this number be
  540. changed unless you are very familiar with the 
  541. system and willing to possibly make some 
  542. programming changes since the system has not 
  543. been thoroughly tested on different size 
  544. networks.  If you do change this parameter 
  545. the number chosen should be a square due to 
  546. the way the program displays the state vector.
  547. Also the pattern and matrix files for one
  548. size network will NOT necessarily work for 
  549. other size networks.
  550.  
  551. 2) Evaluation procedure
  552. if this is set to 0 then the evaluation
  553. process will simulated a Hopfield-like network;
  554. set to 1 it will perform evaluation using a 
  555. simulated annealing process similar to that 
  556. used by a Boltzmann machine.
  557.  
  558. 3) Percent of nodes firing per cycle
  559. this parameter allows the user to specify
  560. what percentage of the nodes in the network 
  561. will be evaluated for firing each cycle.  
  562. When this value is 100 all nodes fire each 
  563. cycle, and the network becomes synchronous 
  564. and deterministic.  By decreasing this
  565. value operation becomes asynchronous (i.e. nodes
  566. no longer fire in order, one after another) and
  567. the system is no longer deterministic (i.e. the
  568. same initial pattern may settle into different 
  569. final states on different occasions).  The 
  570. rationale for this parameter is that it is 
  571. intended to simulate part of the asynchronous 
  572. behavior of biological neurons, and also it
  573. helps to keep the system from getting caught
  574. in weak local minima as opposed to the desired 
  575. strongest close minima.
  576.  
  577. 4) Single node threshold value
  578. by increasing the threshold you increase
  579. the amount of input that a node must receive 
  580. from other nodes in order to turn on.  The 
  581. effect this has on recall varies depending 
  582. upon the weight matrix, but it seems to be 
  583. most useful in conjunction with the Hebbian
  584. rules which otherwise have difficulty retrieving
  585. the original patterns without noise.  This
  586. parameter can also make the network "forget" 
  587. certain memories and recall instead their 
  588. linear superpositions.
  589.  
  590. 5) Learning rule
  591. select one of the following:
  592.    Hopfield (2Vi - 1)(2Vj - 1)
  593.    Hebbian  Vi * Vj
  594.    Hebbian/anti-Hebbian (2Vi - 1) * Vj
  595.  
  596. It is helpful to draw up the truth tables
  597. for these rules to see how they effect the 
  598. weights between nodes of different activation. 
  599. The Hopfield rule is the most effect for 
  600. associative recognition which is the primary 
  601. use for a network of this size and design.
  602.  
  603. 6) Input bias
  604. this parameter determines how much
  605. influence the initial "cue" pattern should 
  606. have on the settling of the network.  When
  607. set to 0 the settling process is only 
  608. influenced by the input pattern on the first 
  609. cycle.  Setting it to one or more biases each 
  610. node towards being in its initial cue state 
  611. on all future cycles (the greater the factor the
  612. greater the biasing).
  613.  
  614. 4) display/change state vector
  615. displays the current state vector and allows it to be 
  616. changed by either loading an existing pattern file or 
  617. changing the current pattern.  Changing the current pattern 
  618. involves the use of a simple visual pattern editor in which 
  619. you can change the state of each individual node in the network.  
  620.  
  621. 5) save state vector in file
  622. saves the current state vector in a file named by the user 
  623. (only one pattern per file).
  624.  
  625. 6) display weight matrix
  626. displays the individual weights stored in the weight matrix.  
  627. The standard weight matrix size is 25 by 25 with entry Wij
  628. representing the connection weight between the ith and jth 
  629. nodes.
  630.  
  631. 7) load matrix from file
  632. lists the names of existing weight matrix files and
  633. allows the user to select one to be loaded into the weight 
  634. matrix.
  635.  
  636. 8) save matrix in file
  637. saves the current weight matrix in a file named by
  638. the user.  This is often useful since the learning process 
  639. can be tedious.
  640.  
  641. 9) quit
  642. exits from the program.  This can also be accomplished at
  643. any time using ^C or BREAK (provided your PC is setup for 
  644. breaking).
  645.  
  646.  
  647. The program is designed to be relatively simple to use.  All prompts have
  648. assigned defaults which are indicated between brackets (e.g. <NO>);  the
  649. default with be assumed if the user does not provide a value (i.e. the user
  650. simply hits the carriage return).
  651.  
  652. The general procedure for using the system is as follows:
  653.  
  654.       * Enter basic and run NEUROSIM
  655.  
  656.       * Configure the network by selecting values for the various
  657. parameters (not necessary if the default Hopfield-like network is used).
  658.  
  659.       * Teach the network one or more patterns using the "learn" option
  660.   (After creating a pattern and teaching it to the network it is
  661.    usually a good idea to save that pattern in a file (using the
  662.    "save state vector" option) which can then be retrieved later 
  663.    for setting up a pattern for recall).
  664. OR
  665. Load a weight matrix from an existing file.
  666.  
  667.       * Select the recall option and create a pattern to be recalled by the
  668. network.  To see how well a network recalls its patterns it is best to
  669. create patterns that are slightly distorted from the originally taught
  670. patterns.  If the original patterns where stored in files, then they 
  671. can be loaded into the state vector and distorted using the pattern 
  672. editor.
  673.  
  674.       * Change some parameter(s) and notice the effect it has on recall
  675. and/or learning.
  676.  
  677.       * Save the weight matrix if you intend to continue experimentation.
  678.  
  679. It is hoped that through experimentation with this program you will obtain 
  680. a fuller appreciation for the functioning of neural networks than could be 
  681. obtained from simply reading about them.  
  682.  
  683. Enjoy!                                                        (9-25-86 CJM)
  684.  
  685.  
  686.